#include "SCPlayerPro.h"
#pragma comment(lib, "SCCore.lib")
#pragma comment(lib, "SCUtility.lib")
StreamCaptureCore* capture = NULL;
bool isInitSCPro = false;
bool OpenCapture(const char* url, OutPixFmt outpixfmt /*= OutPixFmt::PIX_FMT_AUTO*/, HWDeviceType hwtype /*= HWDeviceType::HWDEVICE_TYPE_AUTO*/)
{
	if (!isInitSCPro)
	{
		InitializeStreamCapturePro();
		isInitSCPro = true;
	}
	if (capture)
		CloseStreamCapture(capture);
	capture = CreateStreamCapture(NULL);
	SCConfiguration config;
	config.disableAudio = 1;
	config.outputPixfmt = outpixfmt;
	config.hwaccelType = hwtype;
	return OpenStreamCapture(capture, url, &config, NULL) == DEMUX_STATE_SUCCESS ? true : false;
}

SCFrame* GrabFrame()
{
	if (!capture)
		throw;
	SCFrame* frame = NULL;

retry:
	int ret = TryGrabFrame(capture, FRAME_TYPE_VIDEO, frame);
	if (ret < 0)
		throw;
	if (ret == 0)
		goto retry;

	FrameMoveToLast(capture, FRAME_TYPE_VIDEO);
	if (frame->context_type == FRAME_CONTEXT_TYPE_EOF)
		goto retry;
	return frame;
}
